<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/axios-0.18.0.js"></script>

</head>
<body class="hold-transition">
<div id="app">
    <!--页头-->
    <div class="content-header">
        <h1>健康评估<small>心理测评</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>健康评估</el-breadcrumb-item>
            <el-breadcrumb-item>心理测评</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <!--页面内容-->
    <div class="app-container">
        <div class="box">
            <!--分页表头-->
            <div class="filter-container">
                <el-input placeholder="档案号/姓名" v-model="pagination.queryString" style="width: 200px;" class="filter-item"></el-input>
                <el-button @click="findPage(1)" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>
            <!--分页数据-->

            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>


                <el-table-column type="index" align="center" label="档案号"></el-table-column>
                <el-table-column prop="name" label="姓名" align="center"></el-table-column>
                <el-table-column prop="data" label="心理测评日期" align="center"></el-table-column>
                <el-table-column prop="body" label="躯体化" align="center"></el-table-column>
                <el-table-column prop="obsession" label="强迫症化" align="center"></el-table-column>
                <el-table-column prop="relation" label="人际关系敏感" align="center"></el-table-column>
                <el-table-column prop="hesitation" label="犹豫" align="center"></el-table-column>
                <el-table-column prop="anxiety" label="焦虑" align="center"></el-table-column>
                <el-table-column prop="rivalry" label="敌对" align="center"></el-table-column>
                <el-table-column prop="terrify" label="恐怖" align="center"></el-table-column>
                <el-table-column prop="stubborn" label="偏执" align="center"></el-table-column>
                <el-table-column prop="psychosis" label="精神病性" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        &nbsp&nbsp&nbsp<el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
                <el-table-column label="查看报告" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">查看</el-button>

                    </template>
                </el-table-column>
            </el-table>
            <!--分页栏-->
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增心理测评" :visible.sync="dialogFormVisible">
                    <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right" label-width="100px">
                        <el-row>
                            <el-col :span="9">
                                <el-form-item label="档案号" prop="id" v-model="pagination.queryString">
                                    <el-input v-model="formData.id"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="9">
                                <el-form-item label="姓名"  v-model="pagination.queryString">
                                    <el-input v-model="formData.name"/>
                                </el-form-item>
                            </el-col>
                            <el-button @click="findPage(1)" class="dalfBut">查询</el-button>
                        </el-row>
                    </el-form>
                        <p>心理测评</p>
                        <hr>
                        <p>请根据近一年的感觉，回答以下问题</p>
                        <div class="checkScrol">
                            <table class="datatable">
                                <tbody>
                                <tr v-for="c in tableData">
                                    <td><label :for="c.id">{{c.id}}</label></td>
                                    <td><label :for="c.id">{{c.name}}</label></td>

                                    <td>
                                        <input   type="checkbox" value="0" :value = "c.level">从无
                                    </td>
                                    <td>
                                        <input   type="checkbox" value="1" :value = "c.level">轻度
                                    </td>
                                    <td>
                                        <input   type="checkbox" value="2" :value = "c.level">中度
                                    </td>
                                    <td>
                                        <input   type="checkbox" value="3" :value = "c.level">偏重
                                    </td>
                                    <td>
                                        <input   type="checkbox" value="4" :value = "c.level">严重
                                    </td>

                                </tr>
                                </tbody>
                            </table>
                        </div>


                    <div slot="footer" class="dialog-footer">
                        <el-button @click="cancle2()">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">提交                            </el-button>
                    </div>
                </el-dialog>
            </div>
            <!-- 编辑标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增心理测评" :visible.sync="dialogFormVisible4Edit">
                    <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right" label-width="100px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="姓名" prop="name">
                                    <el-input v-model="formData.name"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="测评日期" prop="data">
                                    <el-input v-model="formData.data"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="躯体化" prop="body">
                                    <el-input v-model="formData.body"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="强迫症化" prop="obsession">
                                    <el-input v-model="formData.obsession"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="人际关系敏感" prop="relation">
                                    <el-input v-model="formData.relation" type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="犹豫" prop="hesitation">
                                    <el-input v-model="formData.hesitation" type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="焦虑" prop="anxiety">
                                    <el-input v-model="formData.anxiety" type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="敌对" prop="rivalry">
                                    <el-input v-model="formData.rivalry" type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="恐怖" prop="terrify">
                                    <el-input v-model="formData.terrify" type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="偏执" prop="stubborn">
                                    <el-input v-model="formData.stubborn" type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="精神病性" prop="psychosis">
                                    <el-input v-model="formData.psychosis" type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="cancel()">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>

<script>
    var vue = new Vue({
        el: '#app',
        data:{
            uid:'',
            heartChooseIds:[], //新增心理健康测评层度
            activeName:'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize:10,
                total:100,
                queryString:null,
            },
            dataList: [],//列表数据
            formData: {},//表单数据
            tableData:[],//新增和编辑表单中对应的检查项列表数据
            checkitemIds:[],//新增和编辑表单中检查项对应的复选框，基于双向绑定可以进行回显和数据提交
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit:false,//控制编辑窗口显示/隐藏
            rules: {//校验规则
                name: [{ required: true, message: '名字为必填项', trigger: 'blur' }],
                data: [{ required: true, message: '日期为必填项', trigger: 'blur' }],
                body: [{ required: true, message: '必填项', trigger: 'change' }],
                obession: [{ required: true, message: '必填项', trigger: 'blur' }],
                relation: [{ required: true, message: '必填项', trigger: 'blur' }],
                hesitation: [{ required: true, message: '必填项', trigger: 'blur' }],
                anxiety: [{ required: true, message: '必填项', trigger: 'blur' }],
                rivalry: [{ required: true, message: '必填项', trigger: 'blur' }],
                terrify: [{ required: true, message: '必填项', trigger: 'blur' }],
                stubborn: [{ required: true, message: '必填项', trigger: 'blur' }],
                psychosis: [{ required: true, message: '必填项', trigger: 'blur' }],
            }
        },
        created() {
            this.findPage();
        },
        methods: {
            //编辑
            handleEdit() {
                axios.post("/health/edit.do",this.formData).then((res)=>{
                    if (res.data.flag){
                        //弹出提示信息
                        this.$message({
                            message:res.data.message,
                            type:'success'
                        });
                    }else {
                        //失败
                        this.$message.error(res.data.message);
                    }
                }).finally(()=>{
                    //新增成功或失败后，重新调用分页查询方法，查询新的数据
                    this.findPage();
                    //关闭编辑窗口
                    this.dialogFormVisible4Edit = false;
                });
            },
            //添加
            handleAdd () {
                //全局校验
                this.$refs['dataAddForm'].validate((valid)=> {
                    if (valid) {
                        //发送ajax请求，将数据传到后台
                        axios.post("/health/add.do?checkitemIds=" + this.checkitemIds, this.formData).then((res) => {
                            if (res.data.flag) {
                                //弹出提示信息
                                this.$message({
                                    message: res.data.message,
                                    type: 'success'
                                });
                            } else {
                                //失败
                                this.$message.error(res.data.message);
                            }
                        }).finally(() => {
                            //成功,关闭新增窗口
                            this.dialogFormVisible = false;
                            //新增成功后，重新调用分页查询方法，查询新的数据
                            this.findPage();
                        });
                    }else {
                        //校验不通过，return，false
                        this.$message.error("数据校验失败，请检查");
                        return false;
                    }
                });
            },
            //分页查询
            findPage(page) {
                if (page == 1){
                    this.pagination.currentPage = page;
                }
                var param= {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                };
                axios.post("/health/findPage.do",param).then((res)=>{
                    this.pagination.total = res.data.total;
                    this.dataList = res.data.rows;
                });

            },
            //校验残留：上一次表单关闭时，校验未通过的提示信息在下一次打开新建表单时提示还会存在
            //点击取消时，弹出的添加表单关闭，且清空校验残留
            handleCancle() {

                this.dialogFormVisible = false; //这个属性是用来控制 新增表单页面的显示的的
                this.$refs["dataAddForm"].clearValidate();//移除校验结果
                this.$refs["dataAddForm"].resetFields(); //移除校验结果并重置字段值

            },
            //取消编辑表单
            cancel(){
                this.dialogFormVisible4Edit = false;
                this.resetForm();
                this.handleCancle();
            },
            //取消新建表单
            cancle2(){
                this.dialogFormVisible = false;
                this.resetForm();
                this.handleCancle();
            },
            // 重置表单
            resetForm() {
                this.formData = {};
                //重置为基本信息
                this.activeName = 'first';
                //重置复选框
                this.checkitemIds = [];
            },
            // 弹出添加窗口
            handleCreate() {
                this.dialogFormVisible = true;
                this.resetForm();
                axios.get("/health/findAll.do").then((res)=>{
                    if (res.data.flag){
                        //成功进行赋值
                        this.tableData = res.data.data;
                    }else {
                        //失败
                        this.$message.error(res.data.message);
                    }
                });

            },
            // 弹出编辑窗口
            handleUpdate(row) {
                this.dialogFormVisible4Edit = true;

                //发送ajxs请求查询检查组基本数据
                axios.get("/health/findById.do?id="+row.id).then((res)=>{
                    if (res.data.flag){
                        //进行回显
                        this.formData = res.data.data;
                        //把返回的数据里面的用户id赋值给页面
                        this.uid = res.data.data.id;
                    }else {
                        //查询失败
                        this.$message.error(res.data.message);
                    }
                });

            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            // 删除
            handleDelete(row) {
                axios.post("/health/delete.do?id="+ row.id).then((res)=>{
                    if(res.data.flag){
                        //删除成功
                        this.$message({
                            type:'success',
                            message:res.data.message
                        })
                    }else{
                        //删除失败
                        this.$message.error(res.data.message);
                    }
                }).finally(()=>{
                    //不管删除是否成功，都调用重新查询的方法
                    this.findPage()
                })

            }
        }
    })
</script>
</html>
